package com.xcf.controller.business.common;


import java.util.List;

import javax.annotation.Resource;

import org.drools.compiler.lang.DRL5Expressions.expression_return;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xcf.controller.base.BaseController;
import com.xcf.entity.Page;
import com.xcf.service.business.common.routeattachfee.RouteAttachFeeService;
import com.xcf.util.PageData;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/** 
 * 航线附加费
 * 类名称：RouteAttchFeeController
 * 创建人：tanwei
 * 更新时间：2017年11月22日
 * @version
 */
@Controller
@RequestMapping("/routeAttchFee")
public class RouteAttachFeeController extends BaseController{
	String menuUrl = "routeAttchFee/list";
	@Resource
	private RouteAttachFeeService routeAttachFeeService;
	/**
	 * 航线附加费列表查询
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/list")
	public ModelAndView routeAttchFeeList(Page page)throws Exception{
		ModelAndView view = new ModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		page.setPd(pd);
		List<PageData> routeAttachFee = routeAttachFeeService.findRouteAttachFeeInfo(pd);
		view.addObject("routeAttachFee", routeAttachFee);
		view.setViewName("/business/common/routeattachfee/route_attach_fee_list");
		return view;
		
	}
	/**
	 * 保存或者更新航线附加费信息
	 * @throws Exception
	 */
	@RequestMapping("/saveOrupdateInfo")
	@ResponseBody
	public String saveOrupdateInfo() throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		if(pd.getString("ID")==null || pd.getString("ID")==""){
			routeAttachFeeService.saveRouteAttachFeeInfo(pd);
			}else{
			routeAttachFeeService.updateRouteAttachFeeInfo(pd);
			}
		return null;
	}
	/**
	 * 修改航线附加费信息页面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editRouteAttachFee")
	public ModelAndView editRouteAttachFee() throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		ModelAndView view = new ModelAndView();
		pd = routeAttachFeeService.findRouteAttachFeeInfoById(pd);
		view.addObject("pd", pd);
		view.setViewName("/business/common/routeattachfee/route_attach_fee_edit");
		return view;
		
	}
	/**
	 * 删除航线附加费信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/deleteRouteAttachFee")
	@ResponseBody
	public String deleteRouteAttachFee() throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		routeAttachFeeService.deleteRouteAttachFeeInfo(pd);
		return null;
		
	}
	/**
	 * 批量删除航线附加费信息
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteRouteAttachFeeAll")
	@ResponseBody
	public String deleteRouteAttachFeeAll() throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		String data = pd.getString("dataJsonStr");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("ID").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			routeAttachFeeService.deleteRouteAttachFeeInfo(pdq);
		}
		return null;
		
	}
}
